package com.itheima.mapper;

import com.itheima.domain.Order;
import com.itheima.domain.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderMapper {
    @Select("SELECT *,o.id oid FROM orders o,USER u WHERE o.uid=u.id")
    @Results({
            @Result(column = "oid", property = "id"),
            @Result(column = "ordertime", property = "ordertime"),
            @Result(column = "total", property = "total"),
            @Result(column = "uid", property = "user.id"),
            @Result(column = "username", property = "user.username"),
            @Result(column = "password", property = "user.password")
    })
    List<Order> findAll();//一对一

    @Select("SELECT * FROM orders")
    @Results({
            @Result(column = "oid", property = "id"),
            @Result(column = "ordertime", property = "ordertime"),
            @Result(column = "total", property = "total"),
            @Result(property = "user",javaType = User.class,
                    column = "uid",
                    //有uid列,调用另一个查询方法,返回一个user
                    one = @One(select = "com.itheima.mapper.UserMapper.findById"))
    })
    List<Order> findAll2();//一对一 相当于连续两个查询语句,把最终结果封装到一起

    @Select("SELECT * FROM orders where uid=#{uid}")
    List<Order> findByUid(int uid);
}
